package com.Apo1o.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Auther: Apo1o.
 * @Date: 2023/10/25-10-25-11:03
 * @Description： 统一响应封装类
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    //业务状态码
    private int code;
    //消息提示 弹窗
    private String msg;
    //数据 查询结果  建议使用泛型
    private Object data;

    //重载响应成功的方法
    public static Result success() {
        return Result.builder()
                .code(ResultCode.SUCCESS.getCode())
                .msg(ResultCode.SUCCESS.getMsg())
                .build();
    }

    public static Result success(String msg) {
        return Result.builder()
                .code(ResultCode.SUCCESS.getCode())
                .msg(msg)
                .build();
    }

    //响应成功的方法
    public static Result success(Object data) {
        return Result.builder()
                .code(ResultCode.SUCCESS.getCode())
                .msg(ResultCode.SUCCESS.getMsg())
                .data(data)
                .build();
    }

    //失败
    public static Result failure() {
        return Result.builder()
                .code(ResultCode.FAILURE.getCode())
                .msg(ResultCode.FAILURE.getMsg())
                .build();
    }

    public static Result failure(String msg) {
        return Result.builder()
                .code(ResultCode.FAILURE.getCode())
                .msg(msg)
                .build();
    }
    public static Result failure(ResultCode resultCode) {
        return Result.builder()
                .code(resultCode.getCode())
                .msg(resultCode.getMsg())
                .build();
    }

}


